import { defineAsyncComponent, Ref as VueRef } from "vue";
import * as md from "../index";
import type { ElButton, ElCascader, ElDatePicker, ElInput, ElInputNumber, ElSwitch, ElTreeSelect, TableColumnInstance } from "element-plus";

const imgMode = [
  "scaleToFill",// 缩放  不保持纵横比缩放图片，使图片的宽高完全拉伸至填满 image 元素
  "aspectFit",// 缩放  保持纵横比缩放图片，使图片的长边能完全显示出来。也就是说，可以完整地将图片显示出来。
  "aspectFill",// 缩放  保持纵横比缩放图片，只保证图片的短边能完全显示出来。也就是说，图片通常只在水平或垂直方向是完整的，另一个方向将会发生截取。
  "widthFix",// 缩放  宽度不变，高度自动变化，保持原图宽高比不变
  "heightFix",// 缩放  高度不变，宽度自动变化，保持原图宽高比不变 App 和 H5 平台 HBuilderX 2.9.3+ 支持、微信小程序需要基础库 2.10.3
  "top",// 裁剪  不缩放图片，只显示图片的顶部区域
  "bottom",// 裁剪  不缩放图片，只显示图片的底部区域
  "center",// 裁剪  不缩放图片，只显示图片的中间区域
  "left",// 裁剪  不缩放图片，只显示图片的左边区域
  "right",// 裁剪  不缩放图片，只显示图片的右边区域
  "top left",// 裁剪  不缩放图片，只显示图片的左上边区域
  "top right",// 裁剪  不缩放图片，只显示图片的右上边区域
  "bottom left",// 裁剪  不缩放图片，只显示图片的左下边区域
  "bottom right",// 裁剪  不缩放图片，只显示图片的右下边区域
] as const;
export declare namespace GT {
  type ImgMode = typeof imgMode[number];
  type ns = string | number;
  type int = number;
  // #region 基础
  type Ref<T> = { value: T; };
  type RefIa<T> = T | T[] | VueRef<T | T[]>;
  type textAlign = "center" | "end" | "justify" | "left" | "right" | "start";
  type curd = 0 | 1 | 2 | 3;
  type mcud = "create" | "update" | "delete";
  type Rules<T> = R<T>[];
  type Rp<T> = RequiredKey<QueryPage<T>, "#rule">;

  interface PageData<T> {
    current: number;
    data: Array<T>;
    size: number;
    total: number;
  }
  // #endregion 基础 完毕
  export namespace gl {
    // request, api, msg, upload, onLoaded, createEvent, arrivalEvent, removeEvent
    type request = typeof md.request;
    type api = typeof md.api;
    type msg = typeof md.msg;
    type upload = typeof md.upload;
    type onLoaded = typeof md.onLoaded;
    type next = typeof md.next;
    type reLaunch = typeof md.reLaunch;
    type navigateTo = typeof md.navigateTo;

    type Def = typeof md.def;
    type SqlK = keyof Def;
    type SqlT<T extends SqlK> = Def[T];
    type SqlE = Def[SqlK];
    type Gd = { [k in SqlK]: md.BaseArrSimple<k, Def[k]>; } & {
    };
    type format = typeof md.format;
    type pd = typeof md.pd;
    type pdk = Key<pd>;

    interface UniPage extends obj {
      fullPath: string;
      id: number;
      meta: {
        backgroundColor: string;
        id: number;
        isNVue: boolean;
        navigationBar: {
          "style": "custom" | "default",
          "type": "default" | "transparent" | "float",
          "titleText": string,
          "titleSize": string,
          "titleColor": string,
          "backgroundColor": string;
        } & obj;
        pullToRefresh: obj;
        route: string;
      };
      openType: string;
      options: { [k: string]: string; };
      path: string;
      route: string;
      statusBarStyle: string;
    }
  }
  //#region 项目专用
  interface FileListKey extends obj {
    uid: string;
    path: string;
    name: string;
    type: string;
  }
  /** 坐标 */
  type Coordinates = [number, number];
  /**
   * 选择用户数据
   * @id 用户id
   * @name 用户姓名
   */
  interface choiceUserInfo extends obj {
    id: string;
    name: string;
  }

  //#endregion 专用结束
  namespace components {
    interface RowProps {
      label?: string;
      labelWidth?: string;
      range?: string;
      labelTextAlign?: textAlign;
    }
    type Banner = { url: string; title: string; link: string; } & obj;
    type UploadOther = { type: string; other: obj; };
    type Upload = { url: string; file?: File, upload?: (opt: UploadOther) => Promise<string>; };
    namespace el {
      type ls = RowProps & obj;
      interface input extends ls {
        type: "input";
        value: string;
        opt?: CPN<typeof ElInput> & { onClick?: cbk; };
      }
      interface Number extends ls {
        type: "number";
        value: number;
        opt?: CPN<typeof ElInputNumber>;
      }
      interface datePicker extends ls {
        type: "datePicker";
        value: CP<typeof ElDatePicker>["modelValue"];
        opt?: CPN<typeof ElDatePicker>;
      }
      interface treeSelect extends ls {
        value: any;
        type: "treeSelect";
        opt?: CPN<typeof ElTreeSelect>;
      }
      interface cascader extends ls {
        value: any;
        type: "cascader";
        opt: RequiredKey<CPN<typeof ElCascader>, ["props", "options"]>;
      }
      interface button extends ls {
        value: any;
        type: "button";
        opt?: CP<typeof ElButton>;
      }
      interface Switch extends ls {
        value: any;
        type: "switch";
        opt?: CP<typeof ElSwitch>;
      }
    }
    type Filter = el.input | el.Number | el.datePicker | el.treeSelect | el.cascader | el.button | el.Switch;
    type ElTableColumn = Partial<TableColumnInstance["$props"]>;
  }
  namespace other {
    interface EventBusHandle { type: RegExp; callBack: (data: any) => void; }
    type ElRule = { required?: boolean; trigger?: "blur" | "change"; }
      & ({ message: string; }
        | { message: string; min: number; max: number; }
        | { validator: (rule: obj, value: any, cbk: cbk) => void; });
    interface ElRules {
      [k: string]: ElRule;
    }
    interface SettingRules {
      [k: string]: {
        message: string;
        cmp: ReturnType<typeof defineAsyncComponent>;
        label?: string;
        popt?: obj;
        opt?: obj;
        required?: boolean;
        trigger?: "blur" | "change";
        min?: number; max?: number;
      };
    }
  }
}
export default GT;